/* Copyright (C) 2016-2018 Alibaba Group Holding Limited

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#ifndef TDM_SERVING_BIZ_FILTER_MANAGER_H_
#define TDM_SERVING_BIZ_FILTER_MANAGER_H_

#include <string>
#include "util/conf_parser.h"
#include "util/singleton.h"
#include "util/concurrency/mutex.h"

namespace tdm_serving {

class Filter;

// Filter Manager manages all filter instances,
class FilterManager : public util::Singleton<FilterManager> {
 public:
  FilterManager();
  ~FilterManager();

  // Initialize by filter conf file,
  bool Init(const std::string& conf_path);

  void Reset();

  // Get filter by name
  Filter* GetFilter(const std::string& filter_name);

 private:
  typedef std::map<std::string, Filter*> FilterMap;
  FilterMap filter_map_;

  util::SimpleMutex mutex_;
  bool inited_;

  DISALLOW_COPY_AND_ASSIGN(FilterManager);
};

}  // namespace tdm_serving

#endif  // TDM_SERVING_BIZ_FILTER_MANAGER_H_
